package com.manualtrader.frame;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import com.manualtrader.trader.ManualTrader;


public abstract class AbstractTableUI extends JScrollPane {

	private static final long serialVersionUID = 1L;

	protected DefaultTableModel tableModel = new DefaultTableModel() {
		public boolean isCellEditable(int row, int column) {
			return table.getColumnModel().getColumn(column).getCellRenderer() instanceof TableCellEditor;
		}
	};

	protected JTable table = new JTable(tableModel);

	public AbstractTableUI() {
		table.getTableHeader().setResizingAllowed(true);
		table.getTableHeader().setReorderingAllowed(true);
		table.getTableHeader().setFont(UIManager.getFont("Label.font"));
		TableColumnBean[] columns = getTableColumn();
		tableModel.setColumnIdentifiers(columns);
		
		for (int i = 0; i < columns.length; i++) {
			TableColumn currColumn = table.getColumnModel().getColumn(i);
			TableCellRenderer cellRenderer = columns[i].getCellRenderer();

			currColumn.setCellRenderer(cellRenderer);
			if (cellRenderer instanceof TableCellEditor) {
				currColumn.setCellEditor((TableCellEditor) cellRenderer);
			}
		}

		this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

		this.setViewportView(table);

	}
	
	public void startRefresh(){
		initTableData();
	}
	
	protected abstract TableColumnBean[] getTableColumn();

	protected abstract void initTableData();
	

}
